package com.lineage.server.serverpackets;

import com.lineage.server.model.Instance.L1PcInstance;

public class S_OtherCharPacks extends ServerBasePacket {
  private static final int STATUS_POISON = 1;
  
  private static final int STATUS_INVISIBLE = 2;
  
  private static final int STATUS_PC = 4;
  
  private static final int STATUS_BRAVE = 16;
  
  private static final int STATUS_ELFBRAVE = 32;
  
  private static final int STATUS_FASTMOVABLE = 64;
  
  private byte[] _byte;
  
  public S_OtherCharPacks(L1PcInstance pc) {
    this._byte = null;
    int status = 4;
    if (pc.getPoison() != null && pc.getPoison().getEffectId() == 1)
      status |= 0x1; 
    if (pc.isInvisble())
      status |= 0x2; 
    if (pc.isBrave())
      status |= 0x10; 
    if (pc.isElfBrave()) {
      status |= 0x10;
      status |= 0x20;
    } 
    if (pc.isFastMovable())
      status |= 0x40; 
    writeC(87);
    writeH(pc.getX());
    writeH(pc.getY());
    writeD(pc.getId());
    if (pc.isDead()) {
      writeH(pc.getTempCharGfxAtDead());
    } else {
      writeH(pc.getTempCharGfx());
    } 
    if (pc.isDead()) {
      writeC(pc.getStatus());
    } else if (pc.isFishing()) {
      writeC(71);
    } else if (pc.isPrivateShop()) {
      writeC(70);
    } else {
      writeC(pc.getCurrentWeapon());
    } 
    writeC(pc.getHeading());
    writeC(pc.getChaLightSize());
    writeC(pc.getMoveSpeed());
    writeD(0);
    writeH(pc.getLawful());
    if (pc.isProtector()) {
      writeS("**守护者**");
    } else {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.append(pc.getViewName());
      if (pc.get_other().get_color() != 0)
        stringBuilder.append(pc.get_other().color()); 
      if (pc.get_c_power() != null && pc.get_c_power().get_c1_type() != 0 && 
        pc.get_c_power().get_power().get_c1_name_title() != null) {
        String type = pc.get_c_power().get_power().get_c1_name_type();
        stringBuilder.append(type);
      } 
      writeS(stringBuilder.toString());
    } 
    writeS(pc.getTitle());
    writeC(status);
    writeD(pc.getEmblemId());
    writeS(pc.getClanname());
    writeS(null);
    writeC(pc.getClanRank() << 4);
    writeC(255);
    if (pc.hasSkillEffect(998)) {
      writeC(8);
    } else {
      writeC(0);
    } 
    writeC(0);
    writeC(0);
    writeC(255);
    writeC(255);
  }
  
  public S_OtherCharPacks(L1PcInstance pc, int gm) {
    this._byte = null;
    int status = 4;
    if (pc.getPoison() != null && pc.getPoison().getEffectId() == 1)
      status |= 0x1; 
    if (pc.isBrave())
      status |= 0x10; 
    if (pc.isElfBrave()) {
      status |= 0x10;
      status |= 0x20;
    } 
    if (pc.isFastMovable())
      status |= 0x40; 
    writeC(87);
    writeH(pc.getX());
    writeH(pc.getY());
    writeD(pc.getId());
    if (pc.isDead()) {
      writeH(pc.getTempCharGfxAtDead());
    } else {
      writeH(pc.getTempCharGfx());
    } 
    if (pc.isDead()) {
      writeC(pc.getStatus());
    } else if (pc.isFishing()) {
      writeC(71);
    } else if (pc.isPrivateShop()) {
      writeC(70);
    } else {
      writeC(pc.getCurrentWeapon());
    } 
    writeC(pc.getHeading());
    writeC(pc.getChaLightSize());
    writeC(pc.getMoveSpeed());
    writeD(0);
    writeH(pc.getLawful());
    if (pc.isProtector()) {
      writeS("**守护者**");
    } else {
      StringBuilder stringBuilder = new StringBuilder();
      stringBuilder.append(pc.getViewName());
      if (pc.get_other().get_color() != 0)
        stringBuilder.append(pc.get_other().color()); 
      if (pc.get_c_power() != null && pc.get_c_power().get_c1_type() != 0 && 
        pc.get_c_power().get_power().get_c1_name_title() != null) {
        String type = pc.get_c_power().get_power().get_c1_name_type();
        stringBuilder.append(type);
      } 
      writeS(stringBuilder.toString());
    } 
    writeS(pc.getTitle());
    writeC(status);
    writeD(pc.getEmblemId());
    writeS(pc.getClanname());
    writeS(null);
    writeC(pc.getClanRank() << 4);
    writeC(255);
    if (pc.hasSkillEffect(998)) {
      writeC(8);
    } else {
      writeC(0);
    } 
    writeC(0);
    writeC(0);
    writeC(255);
    writeC(255);
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
